summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulian de Bhal <julian.debhal@nokia.com>2011-07-05 10:38:15 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-06 05:52:57 +0200
commitee6774456e8e329e073dfe26c9ec84fd504d12c3 (patch)
tree2b8c17cb0911fd6d789074e49ab142fdeacb4959
parentccfd4a120900a86b971d95fea582d5f72f53fca6 (diff)
Documentation, autotests and examples for Item3D modelview
Change-Id: I63cbd719938c12e686026d6465a733a060d35538 Reviewed-on: http://codereview.qt.nokia.com/1135 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Sarah Jane Smith
-rw-r--r--examples/quick3d/photoroom/qml/PhotoPane.qml11
-rw-r--r--examples/quick3d/photoroom/qml/photoroom.qml114
-rw-r--r--src/quick3d/qdeclarativeitem3d.cpp31
l---------tests/auto/qml3d/modelview/textures1
-rw-r--r--tests/auto/qml3d/modelview/tst_modelview.qml269
5 files changed, 365 insertions, 61 deletions
diff --git a/examples/quick3d/photoroom/qml/PhotoPane.qml b/examples/quick3d/photoroom/qml/PhotoPane.qml
index 235af894..6120a635 100644
--- a/examples/quick3d/photoroom/qml/PhotoPane.qml
+++ b/examples/quick3d/photoroom/qml/PhotoPane.qml
@@ -44,15 +44,15 @@ import Qt3D 1.0
Item3D {
id: photo
- property real offset
property real layer
property variant image
property bool bounce: false
+ property string color: "#ffffff"
mesh: Mesh { source: "photopane.obj" }
- position: Qt.vector3d(offset, 0, -layer)
- effect: Effect { decal: true; texture: image }
+ position: Qt.vector3d(0, 0, -layer)
+ effect: Effect { decal: true; texture: image; color: photo.color }
onClicked: {
if (photo.state == "pulled_out")
@@ -76,7 +76,8 @@ Item3D {
name: "pulled_out"
PropertyChanges {
target: photo
- x: 0
+ // Center item in the X axis
+ x: -parent.x
}
PropertyChanges {
target: photo
@@ -95,7 +96,7 @@ Item3D {
name: "returned"
PropertyChanges {
target: photo
- x: offset
+ x: 0
}
PropertyChanges {
target: photo
diff --git a/examples/quick3d/photoroom/qml/photoroom.qml b/examples/quick3d/photoroom/qml/photoroom.qml
index 228a984e..4283535b 100644
--- a/examples/quick3d/photoroom/qml/photoroom.qml
+++ b/examples/quick3d/photoroom/qml/photoroom.qml
@@ -54,68 +54,70 @@ Viewport {
center: Qt.vector3d(0, 0, -2.5)
}
- PhotoPane {
- offset: -2.1
- layer: 0
- image: "textures/woman.jpg"
- }
- PhotoPane {
- offset: -2.1
- layer: 1
- image: "textures/niagara_falls.jpg"
- }
- PhotoPane {
- offset: -2.1
- layer: 2
- image: "textures/place.jpg"
- }
- PhotoPane {
- offset: -2.1
- layer: 3
- image: "textures/background.jpg"
- }
- PhotoPane {
- offset: -2.1
- layer: 4
- image: "textures/basket.jpg"
- }
- PhotoPane {
- offset: -2.1
- layer: 5
- image: "textures/qtlogo.png"
- effect.color: "#006090"
+ ListModel {
+ id: imagesModelLeft
+ ListElement { image: "textures/woman.jpg"; }
+ ListElement { image: "textures/niagara_falls.jpg"; }
+ ListElement { image: "textures/place.jpg"; }
+ ListElement { image: "textures/basket.jpg"; }
+ ListElement { image: "textures/qtlogo.png"; color: "#006090" }
}
- PhotoPane {
- offset: 2.1
- layer: 0
- image: "textures/niagara_falls.jpg"
- }
- PhotoPane {
- offset: 2.1
- layer: 1
- image: "textures/place.jpg"
+ Component {
+ id: paneComponent
+ PhotoPane {
+ layer: index
+ image: model.image
+ // Items end up with the default value defined in PhotoPane if you
+ // try and assign an undefined value, but this logic avoids a
+ // string of warnings
+ color: (model.color == undefined) ? "#ffffff" : model.color
+ }
}
- PhotoPane {
- offset: 2.1
- layer: 2
- image: "textures/background.jpg"
+
+ Item3D {
+ // Left stack of images
+ x: -2.1
+ Repeater {
+ delegate: paneComponent
+ model: imagesModelLeft
+ }
}
- PhotoPane {
- offset: 2.1
- layer: 3
- image: "textures/basket.jpg"
+
+ //! [0]
+ ListModel {
+ id: exampleModel
+ ListElement { image: "textures/niagara_falls.jpg" }
+ ListElement { image: "textures/place.jpg" }
+ ListElement { image: "textures/background.jpg" }
+ ListElement { image: "textures/basket.jpg" }
+ ListElement { image: "textures/woman.jpg" }
}
- PhotoPane {
- offset: 2.1
- layer: 4
- image: "textures/qtlogo.png"
- effect.color: "#006090"
+ //! [0]
+
+ //! [1]
+ Component {
+ id: exampleDelegate
+ PhotoPane {
+ layer: index
+ image: model.image
+ // If you intend on removing elements from the model,
+ // include this line:
+ enabled: index != -1
+ }
}
- PhotoPane {
- offset: 2.1
- layer: 5
- image: "textures/button/woman.jpg"
+ //! [1]
+
+ Item3D {
+ // Right stack of images
+ x: 2.1
+ //! [2]
+ Repeater {
+ id: exampleRepeater
+ delegate: exampleDelegate
+ model: exampleModel
+ }
+ //! [2]
}
states: [
diff --git a/src/quick3d/qdeclarativeitem3d.cpp b/src/quick3d/qdeclarativeitem3d.cpp
index b0c13cd6..7141b550 100644
--- a/src/quick3d/qdeclarativeitem3d.cpp
+++ b/src/quick3d/qdeclarativeitem3d.cpp
@@ -219,6 +219,37 @@
It should be noted that no support is currently provided for skeleton animation or
kinematic control of items. This is left to the user to implement as required.
+
+ \section1 Using QML Data Models With Item3D
+
+ QDeclarativeItem3D supports standard \l
+ {http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#qml-data-models}
+ {QML Data Models} with a few caveats.
+
+ QDeclarativeItem3D derives from QtDeclarativeItem, and interacts with
+ the \l{http://doc.qt.nokia.com/4.7/qml-component.html}{Component} element
+ normally. However, there is a delay between between removing an item from
+ a model and the cleaning up the corresponding Item3D, so it is recommended
+ that Item3D based delegates hide themselves when their index is
+ -1 as shown in the photoroom example:
+
+ \snippet quick3d/photoroom/qml/photoroom.qml 1
+
+ However Item3D does not use the width or height properties, so most
+ positioners and views will not work. Use a
+ \l{http://doc.qt.nokia.com/4.7/qml-repeater.html}{Repeater} element to
+ generate Item3Ds from model data. For example:
+
+ \snippet quick3d/photoroom/qml/photoroom.qml 2
+
+ Models can be used normally, so
+\l{http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#listmodel}{ListModel},
+\l{http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#qstringlist}{QStringList}
+ etc. work just like they would with two dimensional Items. For example:
+
+ \snippet quick3d/photoroom/qml/photoroom.qml 0
+
+ \sa{http://doc.qt.nokia.com/4.7/qdeclarativemodels.html#qml-data-models}{QML Data Models}
*/
diff --git a/tests/auto/qml3d/modelview/textures b/tests/auto/qml3d/modelview/textures
new file mode 120000
index 00000000..a55de75f
--- /dev/null
+++ b/tests/auto/qml3d/modelview/textures
@@ -0,0 +1 @@
+/home/debhal/depot/qt/quick3d/examples/quick3d/photoroom/qml/textures \ No newline at end of file
diff --git a/tests/auto/qml3d/modelview/tst_modelview.qml b/tests/auto/qml3d/modelview/tst_modelview.qml
new file mode 100644
index 00000000..c56c1365
--- /dev/null
+++ b/tests/auto/qml3d/modelview/tst_modelview.qml
@@ -0,0 +1,269 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtQuick3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import Qt 4.7
+import Qt3D 1.0
+import Qt3D.Shapes 1.0
+import QtQuickTest 1.0
+
+Rectangle
+{
+ id: topLevel
+ width: 480; height: 480
+
+ Viewport {
+ id: viewport
+ picking: true
+ anchors.fill: parent
+
+ camera: Camera {
+ id: main_camera
+ eye: Qt.vector3d(0, 4, 12)
+ center: Qt.vector3d(0, 0, -2.5)
+ }
+
+ property variant emptyStringListModel:[]
+
+ property variant stringListModelForViewport:[
+ "textures/woman.jpg",
+ "textures/niagara_falls.jpg",
+ "textures/place.jpg",
+ "textures/background.jpg",
+ "textures/basket.jpg",
+ "textures/qtlogo.png"
+ ]
+
+ property variant stringListModelEmptyForItem: []
+
+ property variant stringListModelForItem:[
+ "textures/niagara_falls.jpg",
+ "textures/background.jpg",
+ "textures/place.jpg",
+ "textures/qtlogo.png",
+ "textures/basket.jpg",
+ "textures/woman.jpg"
+ ]
+
+ ListModel {
+ id: listModelForViewport
+ ListElement { image:"textures/woman.jpg"}
+ ListElement { image:"textures/niagara_falls.jpg"}
+ ListElement { image:"textures/place.jpg"}
+ ListElement { image:"textures/background.jpg"}
+ ListElement { image:"textures/basket.jpg"}
+ ListElement { image:"textures/qtlogo.png"}
+ }
+
+ ListModel {
+ id: listModelForItem
+ ListElement { image:"textures/niagara_falls.jpg"}
+ ListElement { image:"textures/background.jpg"}
+ ListElement { image:"textures/place.jpg"}
+ ListElement { image:"textures/qtlogo.png"}
+ ListElement { image:"textures/basket.jpg"}
+ ListElement { image:"textures/woman.jpg"}
+ }
+
+ Component {
+ id: paneComponentstringList
+ Quad {
+ property real layer: index
+ property variant image : modelData
+ position: Qt.vector3d(0, 0, -layer)
+ effect: Effect { decal: true; texture: image }
+ transform: Rotation3D { axis: Qt.vector3d(1,0,0); angle: 90 }
+ }
+ }
+
+ Component {
+ id: paneComponentListModel
+ Quad {
+ position: Qt.vector3d(index * 0.1, 0, -index)
+ enabled: index != -1
+ effect: Effect { decal: true;
+ texture: model.image;
+ }
+ transform: Rotation3D { axis: Qt.vector3d(1,0,0); angle: 90 }
+ }
+ }
+
+ Repeater {
+ id: stringListModelRepeaterInViewport
+ delegate: paneComponentstringList
+ model: parent.stringListModelEmpty
+ }
+
+ Repeater {
+ id: listModelRepeaterInViewport
+ delegate: paneComponentListModel
+ model: listModelForViewport
+ }
+
+ Item3D {
+ id: stringListModelParentItem
+ x: -2.1
+ Repeater {
+ id: stringListModelRepeaterInItem
+ delegate: paneComponentstringList
+ model: viewport.stringListModelEmpty
+ }
+ }
+
+ Item3D {
+ id: listModelParentItem
+ x: 2.1
+ y: 0.5
+
+ Repeater {
+ id: listModelRepeaterInItem
+ delegate: paneComponentListModel
+ model: listModelForItem
+ }
+ }
+
+ TestCase {
+ id: modelViewTestAddingCase
+ name: "Quick3d ModelView Adding Data Test"
+
+ function test_changing_stringList_model() {
+ var viewportEmptyModelChildCount = viewport.children.length;
+ var itemEmptyModelChildCount =
+ stringListModelParentItem.children.length;
+ var modelLength = viewport.stringListModelForViewport.length;
+
+ stringListModelRepeaterInViewport.model =
+ viewport.stringListModelForViewport;
+
+ verify(viewport.children.length >
+ viewportEmptyModelChildCount,
+ "Children not added to viewport with changed stringList model");
+ compare(viewport.children.length,
+ viewportEmptyModelChildCount +
+ viewport.stringListModelForViewport.length,
+ "Viewport has unexpected number of new children");
+
+ stringListModelRepeaterInItem.model =
+ viewport.stringListModelForItem;
+
+ verify(stringListModelParentItem.children.length >
+ itemEmptyModelChildCount,
+ "Children not added to Item3D with changed stringList model");
+ compare(stringListModelParentItem.children.length,
+ itemEmptyModelChildCount +
+ viewport.stringListModelForItem.length,
+ "Item3D has unexpected number of new children");
+ }
+
+ function test_adding_to_listModel() {
+ var viewportChildCount = viewport.children.length;
+ var itemChildCount = listModelParentItem.children.length;
+
+ listModelForViewport.append({"image":"textures/background.jpg"});
+ listModelForItem.append({"image":"textures/background.jpg"});
+ viewport.update3d();
+ compare(viewport.children.length, viewportChildCount + 1,
+ "Viewport missing child after listModel.append()");
+ compare(listModelParentItem.children.length,
+ itemChildCount + 1,
+ "Item3D missing child after listModel.append()");
+ }
+ }
+
+ // This timer is to avoid an issue where removing children is
+ // delayed during initialization.
+ Timer {
+ running: true
+ interval: 1
+ onTriggered: modelViewRemovingItemsTestCase.when = true;
+ }
+
+ TestCase {
+ id: modelViewRemovingItemsTestCase
+ // Wait for event loop before performing removal tests
+ when: false
+ name: "Quick3d ModelView Removing Data Test"
+
+ function test_removing_from_listModel() {
+ var viewportChildCount = viewport.children.length;
+ var itemChildCount = listModelParentItem.children.length;
+
+ listModelForViewport.remove(listModelForViewport.count - 1);
+ compare(viewport.children.length, viewportChildCount -1,
+ "Viewport has extra children after listModel.remove()")
+
+ listModelForItem.remove(listModelForItem.count -1);
+ compare(listModelParentItem.children.length,
+ itemChildCount - 1,
+ "Item3D has extra children after listModel.remove()");
+ }
+
+ function test_clearing_stringList() {
+ stringListModelRepeaterInViewport.model =
+ viewport.stringListModelForViewport;
+ stringListModelRepeaterInItem.model =
+ viewport.stringListModelForItem;
+
+ var viewportChildCount = viewport.children.length;
+ var itemChildCount = stringListModelParentItem.children.length;
+
+ stringListModelRepeaterInViewport.model =
+ viewport.emptyStringListModel;
+ stringListModelRepeaterInItem.model =
+ viewport.emptyStringListModel;
+
+ verify(viewport.children.length < viewportChildCount,
+ "Children not removed from viewport when clearing stringList model");
+ compare(viewport.children.length,
+ viewportChildCount -
+ viewport.stringListModelForViewport.length,
+ "Unexpected number of children after setting empty model");
+
+ verify(stringListModelParentItem.children.length <
+ itemChildCount,
+ "Children not removed from Item3D when clearing stringList model");
+ compare(stringListModelParentItem.children.length,
+ itemChildCount -
+ viewport.stringListModelForItem.length,
+ "Unexpected number of children after setting empty model");
+ }
+ }
+ }
+}